package com.gperp.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gperp.common.CustomerResCondition;
import com.gperp.common.PortalCondition;
import com.gperp.mapper.AsCustomsMapper;
import com.gperp.pojo.AsContacts;
import com.gperp.pojo.AsCustoms;
import com.gperp.pojo.AsCustomsExample;
import com.gperp.pojo.AsSystemconfig;
import com.gperp.pojo.Result;
import com.gperp.service.AsContactsService;
import com.gperp.service.CustomerResService;
@CrossOrigin
@RequestMapping("asCustomer")
@Controller
public class AcCustomsController {

	@Autowired
	public CustomerResService customerResService;
	@Autowired
	public AsContactsService  asContactsService;
	//包含分页，模糊查询	
	@RequestMapping(value="query",method=RequestMethod.POST)
	@ResponseBody
	public Result query(Integer page,Integer rows,CustomerResCondition condition){
		//调用服务查询商品列表
		Result list=customerResService.query(page, rows, condition);
		System.out.println(list.getRows());
		return list;
		
	}
	
	//多表查询客户信息
	@RequestMapping(value="queryById",method=RequestMethod.GET)
	@ResponseBody
	public AsCustoms queryById(Long id){
 		AsCustoms as= customerResService.queryById(id);
		return as;
		
	}
	//修改客户状态
	@RequestMapping(value="update",method=RequestMethod.POST)
	@ResponseBody
	public int update(Integer id,Integer customstatus){
 		int as= customerResService.updatecustomStatus(id, customstatus);
		return as;
		
	}
	/**
	 * //电话联系人
	 * @param id
	 * @return
	 */
	@RequestMapping(value="quertTel",method=RequestMethod.GET)
	@ResponseBody
	public List<AsContacts> quertTel(Long id){
 		List<AsContacts> list= asContactsService.queryGetList(id);
		return list;
		
	}
	
	//修改客户信息
	@RequestMapping(value="updatecustomer",method=RequestMethod.POST)
	@ResponseBody
	public int updatecustomer(AsCustoms asCustoms){
 		int t= customerResService.updateCustomer(asCustoms);
		return t;
		
	}
	
//删除客户信息
@RequestMapping(value="deletecontact",method=RequestMethod.POST)
@ResponseBody
public int deletecontact(Long id){
	int t= asContactsService.delete(id);
	return t;
	
}

//添加客户联系人信息
	@RequestMapping(value="insertcontact",method=RequestMethod.POST)
	@ResponseBody
	public int insertcontact(AsContacts ascontacts){
		int t= asContactsService.insertcontacts(ascontacts);
		return t;
	}
	
	//更改客户联系人信息
	@RequestMapping(value="updatecontact",method=RequestMethod.POST)
	@ResponseBody
	public int updatecontact(AsContacts ascontacts){
		int t= asContactsService.updateContacts(ascontacts);
		return t;
	}
	//添加客户信息
	@RequestMapping(value="insert",method=RequestMethod.POST)
	@ResponseBody
	public AsCustoms insert(AsCustoms asCustoms){
		AsCustoms a=customerResService.insert(asCustoms);
		return a;
	}
	
	//根据客户名称查询客户信息
	@RequestMapping(value="querybycname",method=RequestMethod.GET)
	@ResponseBody
	public List<AsCustoms> queryByCname(String customname){
		List<AsCustoms> a=customerResService.queryByCname(customname);
		return a;
	}
	
	//根据客户名称查询客户信息		============liuzihao 新加：解决客户列表出现停用的
	@RequestMapping(value="queryByCnameStart",method=RequestMethod.GET)
	@ResponseBody
	public List<AsCustoms> queryByCnameStart(String customname){
		List<AsCustoms> a=customerResService.queryByCnameStart(customname);
		return a;
	}
	
	@RequestMapping(value="queryCustomtype",method=RequestMethod.GET)
	@ResponseBody
	public List<AsSystemconfig> queryCustomtype(int configtype){
		List<AsSystemconfig> a=customerResService.queryCustomtype(configtype);
		return a;
	}

}
